package com.ztgf.shopping.api.client.epg;

import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.epg.EpgSectionBO;
import com.ztgf.shopping.models.dto.epg.EpgSectionDTO;
import com.ztgf.shopping.models.service.epg.IEpgSectionService;
import com.ztgf.shopping.models.vo.epg.EpgSectionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 频道栏目控制器
 *
 * @author YUE
 * @create 2020-05-18 11:36
 */

@RestController
@RequestMapping("/api/epgSection")
@Slf4j
@Api(value = "EpgSectionApiController",tags = "频道栏目Api接口")
public class EpgSectionApiController {

    @DubboReference
    private IEpgSectionService epgSectionService;

    /**
     * 频道栏目列表 根据功能id
     * @param moduleId 功能id
     * @return
     */
    @ApiOperation(value = "频道栏目列表 根据功能id",notes = "频道栏目列表 根据功能id")
    @PostMapping("/getListByModuleId")
    public Result<List<EpgSectionVO>> getListByModuleId(Long moduleId){
        EpgSectionBO epgSectionBO = new EpgSectionBO();
        epgSectionBO.setModuleId(moduleId);
        List<EpgSectionVO> epgSectionVOList = epgSectionService.getAndCategory(epgSectionBO);
        return new Result<>(epgSectionVOList);
    }


    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<EpgSectionDTO> get(Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        EpgSectionDTO epgSectionDTO = epgSectionService.selectById(id);
        return new Result<>(epgSectionDTO);
    }

    @ApiOperation(value = "频道栏目列表",notes = "频道栏目列表")
    @PostMapping("/querySelectList")
    public Result<List<EpgSectionDTO>> querySelectList( EpgSectionBO epgSectionBO){
        if(null == epgSectionBO)
            return new Result<>(CodeEnum.FAIL_100002 );
        List<EpgSectionDTO> epgSectionDTOList = epgSectionService.getBySelectSectionInfoNoPage(epgSectionBO);
        return new Result<>(epgSectionDTOList);
    }
}
